<template>
  <!-- 查询条件：部门名称 部门类型 部门状态 -->
  <!-- <el-form :model="form" label-width="auto" :inline="true">
    
    <el-form-item label="部门名称：">
      <el-input v-model="form.departmentName" />
    </el-form-item>

    <el-form-item label="部门类型">
            <el-select v-model="form.departmentTypeId" placeholder="请选择" style="width: 150px;">
                <el-option label="业务销售" value="1" />
                <el-option label="行政管理" value="2" />
            </el-select>
        </el-form-item>
  
    <el-form-item label="部门状态">
            <el-select v-model="form.departmentIsNot" placeholder="请选择" style="width: 150px;">
                <el-option label="启用" value="1" />
                <el-option label="禁用" value="2" />
            </el-select>
        </el-form-item>
  
    <el-form-item>
      <el-button type="danger" @click="getDepartmentList">查询</el-button>
      <el-button type="danger">导出部门信息</el-button>
    </el-form-item>
  </el-form> -->

  <!-- 显示数据 -->
  <el-table :data="departmentList" style="width: 100%">
    <el-table-column prop="departmentId" label="部门编号" />
    <el-table-column prop="departmentName" label="部门名称" />
    <el-table-column prop="departmentTypeName" label="部门类型">
      <template v-slot="scope">
        <el-tag type="primary" v-if="scope.row.departmentName == '1'">行政管理</el-tag>
        <el-tag type="success" v-else-if="scope.row.departmentName == '2'">生产加工</el-tag>
        <el-tag type="success" v-else>业务销售</el-tag>
      </template>
    </el-table-column>
    <!-- <el-table-column prop="name" label="级别" /> -->
    <el-table-column prop="departmentFullName" label="部门全称" />
    <el-table-column prop="departmentHead" label="部门主管" />
    <el-table-column prop="financeHead" label="财务主管" />
    <!-- <el-table-column prop="name" label="操作人" /> -->
    <!-- <el-table-column prop="address" label="操作时间" /> -->
  </el-table>

  <!-- 分页 -->
  <table>
    <tr>
      <!-- 1. -->
      <td>
        <el-pagination v-model:current-page="form.pageIndex" v-model:page-size="form.pageSize" :page-sizes="[2, 4, 6, 8]"
          :size="form.pageSize" :background="true" layout="total,slot, sizes" :total="form.pageCount" prev-text="上一页"
          next-text="下一页" @size-change="handleSizeChange" @current-change="handleCurrentChange">
          数据，每页显示{{ form.pageSize }}条数据，当前第1/{{
            form.pageIndex
          }}页，共{{ form.pageCount }}页。
        </el-pagination>
      </td>
      <!-- 2. -->
      <td>
        <el-pagination v-model:current-page="form.pageIndex" v-model:page-size="form.pageSize" :page-sizes="[2, 4, 6, 8]"
          :size="form.pageSize" :background="true" layout="slot,prev, pager" :total="form.pageCount" prev-text="上一页"
          next-text="下一页" @size-change="handleSizeChange" @current-change="handleCurrentChange">
          <el-button @click="handleCurrentChange(1)">首页</el-button>
        </el-pagination>
      </td>
      <!-- 3. -->
      <td>
        <el-pagination v-model:current-page="form.pageIndex" v-model:page-size="form.pageSize" :page-sizes="[2, 4, 6, 8]"
          :size="form.pageSize" :background="true" layout="next,slot, jumper" :total="form.pageCount" prev-text="上一页"
          next-text="下一页" @size-change="handleSizeChange" @current-change="handleCurrentChange">
          <el-button @click="handleCurrentChange(form.pageCount)">尾页</el-button>
        </el-pagination>
      </td>
    </tr>
  </table>
</template>
<script setup lang="ts">
import { reactive, ref, onMounted } from "vue";
import axios from "axios";
import { useRouter, useRoute } from "vue-router";
const router = useRouter();
const route = useRoute();
//生命周期 钩子函数
onMounted(() => {
  getDepartmentList(); //部门设置-显示
});

//定义变量
const form = reactive({
  // departmentName:'',
  // departmentTypeId:'',
  // departmentIsNot:'',

  pageIndex: 1,
  pageSize: 2,
  totalCount: 0,
  pageCount: 0,
});

//部门设置-显示
const departmentList = ref([]);
const getDepartmentList = () => {
  axios
    .post("http://localhost:5012/api/Sheep/DePartmentList", {
      pagesize: form.pageSize,
      pageindex: form.pageIndex
    })
    .then((res) => {
      console.log(res.data.data);
      departmentList.value = res.data.data.data;
      form.pageCount = res.data.data.pageCount;
      form.totalCount = res.data.data.totalCount;
    })
    .catch((err) => {
      console.log(err);
    });
};
//分页
const handleSizeChange = (val: number) => {
  form.pageSize = val;
  getDepartmentList();
};
const handleCurrentChange = (val: number) => {
  form.pageIndex = val;
  getDepartmentList();
};
</script>